//
//  ARCMacros.h
//  InnerBand
//
// For an explanation of why these work, see:
//
//     http://raptureinvenice.com/arc-support-without-branches/
//
//  Created by John Blanco on 1/28/12.
//  Rapture In Venice releases all rights to this code.  Feel free use and/or copy it openly and freely!
//
// NOTE: __bridge_tranfer is not included here because releasing would be inconsistent.
//       Avoid it unless you're using ARC exclusively or managing it with __has_feature(objc_arc).
//
//  2014-9-25 Wang Weiyang
//  该代码用于混编arc和非arc的工程
//  使用宏定义的字符来代替与内存相关代码，在有arc和没有arc的条件下，可自动切换
//
#ifndef _ARCMACROS_H__
#define _ARCMACROS_H__

#if !defined(__clang__) || __clang_major__ < 3
#ifndef __bridge
#define __bridge
#endif

#ifndef __bridge_retain
#define __bridge_retain
#endif

#ifndef __bridge_retained
#define __bridge_retained
#endif

#ifndef __autoreleasing
#define __autoreleasing
#endif

#ifndef __strong
#define __strong
#endif

#ifndef __unsafe_unretained
#define __unsafe_unretained
#endif

#ifndef __weak
#define __weak
#endif
#endif

#ifndef SAFE_ARC_PROP_ASSIGN
#if __has_feature(objc_arc_weak)
#define SAFE_ARC_PROP_ASSIGN weak
#elif __has_feature(objc_arc)
#define SAFE_ARC_PROP_ASSIGN unsafe_unretained
#else
#define SAFE_ARC_PROP_ASSIGN assign
#endif
#endif

#if __has_feature(objc_arc)
#define SAFE_ARC_PROP_RETAIN strong
#define SAFE_ARC_RETAIN(x) (x)
#define SAFE_ARC_RELEASE(x)
#define SAFE_ARC_AUTORELEASE(x) (x)
#define SAFE_ARC_BLOCK_COPY(x) (x)
#define SAFE_ARC_BLOCK_RELEASE(x)
#define SAFE_ARC_SUPER_DEALLOC()
#define SAFE_ARC_AUTORELEASE_POOL_START() @autoreleasepool {
#define SAFE_ARC_AUTORELEASE_POOL_END() }
#else
#define SAFE_ARC_PROP_RETAIN retain
#define SAFE_ARC_RETAIN(x) ([(x) retain])
#define SAFE_ARC_RELEASE(x) ([(x) release])
#define SAFE_ARC_AUTORELEASE(x) ([(x) autorelease])
#define SAFE_ARC_BLOCK_COPY(x) (Block_copy(x))
#define SAFE_ARC_BLOCK_RELEASE(x) (Block_release(x))
#define SAFE_ARC_SUPER_DEALLOC() ([super dealloc])
#define SAFE_ARC_AUTORELEASE_POOL_START() NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
#define SAFE_ARC_AUTORELEASE_POOL_END() [pool release];
#endif

#endif  /* _ARCMACROS_H_ */